Page({

  /**
   * 页面的初始数据
   */
  data: {
    schema:[
    ],
    formData:{
    },
    title: '',
    result: '',
    remark: '',
    webUrl: '',
    apiName: '',
  },
  onLoad(options) {
    console.log('options', options)
    wx.setNavigationBarTitle({
      title: options.title,
    })
    
    this.setData({
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })
    if(options.zh === 'wx.onUnhandledRejection' || options.zh === 'wx.offUnhandledRejection') {
      wx.onUnhandledRejection((res) => {
        this.setData({
          result: res,
          apiName: this.data.zh === 'wx.onUnhandledRejection' ? 'wx.onUnhandledRejection' : 'wx.offUnhandledRejection'
        })
      })
    } else if(options.zh === 'wx.onPageNotFound') {
      wx.onPageNotFound(res => {
        this.setData({
          result: res,
          apiName: 'wx.onPageNotFound'
        })
      })
    } else if(options.zh === 'wx.onError' || options.zh === 'wx.offError') {
      wx.onError((res) => {
        if(options.zh === 'wx.onError') {
          this.setData({
            result: res,
            apiName: 'wx.onError'
          })
        }
        if(options.zh === 'wx.offError') {
          wx.showModal({
            title: '监听到一个错误',
            showCancel: false,
          })
        }
      })
    } else if(options.zh === 'wx.onAppShow' || options.zh === 'wx.offAppShow') {
      wx.onAppShow(res => {
        if(options.zh === 'wx.onAppShow') {
          this.setData({
            result: res,
            apiName: 'wx.onAppShow'
          })
        }
        if(options.zh === 'wx.offAppShow') {
          wx.showModal({
            title: '切换到了前台',
            showCancel: false,
          })
        }
      })
    } else if(options.zh === 'wx.onAppHide' || options.zh === 'wx.offAppHide') {
      wx.onAppHide(res => {
        if(options.zh === 'wx.onAppHide') {
          this.setData({
            result: res,
            apiName: 'wx.onAppHide'
          })
        }
        if(options.zh === 'wx.offAppHide') {
          wx.showModal({
            title: '切换到了后台',
            showCancel: false,
          })
        }
      })
    }
  },
  getFormData(e) {
    this.setData({
      formData: e.detail.formData
    })
  },
  choose1() {
    new Promise((resolve, reject) => {
      reject('测试promise拒绝+事件戳'+new Date().getTime())
    })
  },
  choose2() {
    wx.navigateTo({
      url: '/pages/url/url',
    })
  },
  choose3() {
    let a;
    a.includes('iphone')
  },
  choose4() {
    wx.offUnhandledRejection()
  },
  choose5() {
    wx.offError()
  },
  choose6() {
    wx.offAppShow()
  },
  choose7() {
    wx.offAppHide()
  }
})